const db = require('./config/connect.js')
const express = require('express')
const ejs = require('ejs')
const path = require('path')
const main = require('./interface/page.js')
const routers = require('./interface/api.js')
const sessionFun = require('./middlewase/session.js')
const app = express()

// 连接数据库
db(()=>{
    app.use(express.urlencoded())
    app.set('view engine','ejs')
    app.set('views',path.resolve(__dirname,'./views'))
    app.use(express.static(path.resolve(__dirname,'./assets')))

    sessionFun(app)

    main(app);
    app.use('/api',routers)
    app.use((req,res,next)=>{ //必须放在所有路由的下面，只有在上面路由匹配不到时才会走404
        res.send('404')
    })
    // 监听端口
    app.listen('3000')
})
